﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebService.BUS;
using System.Data;

namespace WebService
{
    public partial class Category : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void ListView1_Sorting(object sender, ListViewSortEventArgs e)
        {

        }

        protected void ListView1_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            if (e.CommandName == "Insert")
            {
                TextBox txtFname = (TextBox)e.Item.FindControl("txtCategoryName");
                string insertCommand = "Insert into [tbl_Category] ([CategoryName]) Values(N'" + txtFname.Text + "');";
                SqlDataSource1.InsertCommand = insertCommand;
            }
            else if (e.CommandName == "Update")
            {
                TextBox txtId = (TextBox)e.Item.FindControl("txtUpCategoryId");
                TextBox txtName = (TextBox)e.Item.FindControl("txtUpCategoryName");
                string updateCommand = "Update [tbl_Category] set [CategoryName]=N'" + txtName.Text + "' where CategoryId=" + Convert.ToInt32(txtId.Text) + ";";
                SqlDataSource1.UpdateCommand = updateCommand;
            }
            else if (e.CommandName == "Delete")
            {
                TextBox txtId = (TextBox)e.Item.FindControl("txtUpCategoryId");
                string deleteCommand = "delete from [tbl_Category] where CategoryId=" + Convert.ToInt32(txtId.Text);
                SqlDataSource1.DeleteCommand = deleteCommand;
            }
        }
    }
}